package se.webbzon.oschi01.worldcamera;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.ImageObserver;
import java.util.Stack;

import se.webbzon.oschi01.font.HorizontalAlignment;
import se.webbzon.oschi01.font.VerticalAlignment;
import se.webbzon.oschi01.textureset.Texture3D;

public abstract class WorldCameraPane implements WorldCameraDrawable {
	
	// A stack of all the layers in the world camera pane
	private final Stack<WorldCameraLayer> layers;
	
	// An image observer used when drawing images in the world camera pane
	private final ImageObserver observer;
	
	// The current layer of this world camera pane
	private WorldCameraLayer layer;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new abstract world camera pane for rendering of 2D
	 * images and geometries. **/
	public WorldCameraPane(ImageObserver observer, Dimension d) {
		this.observer = observer;
		layers = new Stack<WorldCameraLayer>();
		layer = new WorldCameraLayer(d);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the image observer of this world camera pane. **/
	public ImageObserver getImageObserver() {
		return observer;
	}
	
	/** Draws a layer onto this world camera pane. **/
	public void drawLayer(int x, int y, WorldCameraLayer layer) {
		this.layer.drawLayer(x, y, layer);
	}
	
	/** Pushes another layer on top of the current layer. **/
	public void pushLayer(WorldCameraLayer layer) {
		layers.push(this.layer);
		this.layer = layer;
	}
	
	/** Pops the current layer of the top of all layers. **/
	public WorldCameraLayer popLayer() {
		WorldCameraLayer currentLayer = layer;
		layer = layers.pop();
		return currentLayer;
	}
	
	/** Returns the current layer of this world camera pane. **/
	public WorldCameraLayer getLayer() {
		return layer;
	}

	@Override public void clear() {
		layer.clear();
	}
	
	@Override public void paint(int x, int y, Graphics g, ImageObserver observer) {
		layer.paint(x,y,g,observer);
	}
	
	@Override public void resetTransform() {
		layer.resetTransform();
	}

	@Override public void setTransform(AffineTransform transform) {
		layer.setTransform(transform);
	}
	
	@Override public void getTransform(AffineTransform transform) {
		layer.getTransform(transform);
	}
	
	@Override public void setColor(Color c) {
		layer.setColor(c);
	}
	
	@Override public Color getColor() {
		return layer.getColor();
	}
	
	@Override public void setBackgroundColor(Color c) {
		layer.setBackgroundColor(c);
	}
	
	@Override public Color getBackgroundColor() {
		return layer.getBackgroundColor();
	}
	
	@Override public void setFont(Font f) {
		layer.setFont(f);
	}
	
	@Override public Font getFont() {
		return layer.getFont();
	}
	
	@Override public void setTransparency(float transparency) {
		layer.setTransparency(transparency);
	}
	
	@Override public float getTransparency() {
		return layer.getTransparency();
	}
	
	@Override public void drawRect(int x, int y, int width, int height) {
		layer.drawRect(x,y,width,height);
	}
	
	@Override public void fillRect(int x, int y, int width, int height) {
		layer.fillRect(x, y, width, height);
	}
	
	@Override public void drawOval(int x, int y, int width, int height) {
		layer.drawOval(x, y, width, height);
	}
	
	@Override public void fillOval(int x, int y, int width, int height) {
		layer.fillOval(x, y, width, height);
	}
	
	@Override public void drawLine(int x1, int y1, int x2, int y2) {
		layer.drawLine(x1, y1, x2, y2);
	}

	@Override public void drawPolygon(int x, int y, Polygon p) {
		layer.drawPolygon(x, y, p);
	}

	@Override public void fillPolygon(int x, int y, Polygon p) {
		layer.fillPolygon(x, y, p);
	}

	@Override public void drawImage(Image image, int x, int y) {
		layer.drawImage(image, x, y);
	}

	@Override public void drawImage(Image image, int x, int y, int width, int height) {
		layer.drawImage(image, x, y, width, height);
	}
	
	@Override public void drawTexture(Texture3D texture, int x, int y) {
		layer.drawTexture(texture, x, y);
	}
	
	@Override public void drawTexture(Texture3D texture, int x, int y, int width, int height) {
		layer.drawTexture(texture, x, y, width, height);
	}
	
	@Override public void drawString(String str, int x, int y) {
		layer.drawString(str, x, y);
	}
	
	@Override public void getBoundary(String str, int x, int y, Rectangle r) {
		layer.getBoundary(str, x, y, r);
	}

	@Override public void setHAlignment(HorizontalAlignment alignment) {
		layer.setHAlignment(alignment);
	}
	
	@Override public void setVAlignment(VerticalAlignment alignment) {
		layer.setVAlignment(alignment);
	}
	
	@Override public HorizontalAlignment getHAlignment() {
		return layer.getHAlignment();
	}
	
	@Override public VerticalAlignment getVAlignment() {
		return layer.getVAlignment();
	}
	
	@Override public void clip(int x, int y, int width, int height) {
		layer.clip(x, y, width, height);
	}

}
